package com.ruoyi.web.controller.blogs;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.blogs.domain.BsFaq;
import com.ruoyi.blogs.service.IBsFaqService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问答管理Controller
 * 
 * @author ruoyi
 * @date 2022-11-24
 */
@RestController
@RequestMapping("/blogs/faq")
public class BsFaqController extends BaseController
{
    @Autowired
    private IBsFaqService bsFaqService;

    /**
     * 查询问答管理列表
     */
    @PreAuthorize("@ss.hasPermi('blogs:faq:list')")
    @GetMapping("/list")
    public TableDataInfo list(BsFaq bsFaq)
    {
        startPage();
        List<BsFaq> list = bsFaqService.selectBsFaqList(bsFaq);
        return getDataTable(list);
    }

    /**
     * 导出问答管理列表
     */
    @PreAuthorize("@ss.hasPermi('blogs:faq:export')")
    @Log(title = "问答管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BsFaq bsFaq)
    {
        List<BsFaq> list = bsFaqService.selectBsFaqList(bsFaq);
        ExcelUtil<BsFaq> util = new ExcelUtil<BsFaq>(BsFaq.class);
        util.exportExcel(response, list, "问答管理数据");
    }

    /**
     * 获取问答管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('blogs:faq:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(bsFaqService.selectBsFaqById(id));
    }

    /**
     * 新增问答管理
     */
    @PreAuthorize("@ss.hasPermi('blogs:faq:add')")
    @Log(title = "问答管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsFaq bsFaq)
    {
        bsFaq.setId(IdUtils.fastSimpleUUID());
        return toAjax(bsFaqService.insertBsFaq(bsFaq));
    }

    /**
     * 修改问答管理
     */
    @PreAuthorize("@ss.hasPermi('blogs:faq:edit')")
    @Log(title = "问答管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsFaq bsFaq)
    {
        return toAjax(bsFaqService.updateBsFaq(bsFaq));
    }

    /**
     * 删除问答管理
     */
    @PreAuthorize("@ss.hasPermi('blogs:faq:remove')")
    @Log(title = "问答管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bsFaqService.deleteBsFaqByIds(ids));
    }
}
